home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / bin / sh-versions / metasend.z / metasend
Encoding:
Text File  |  1997-01-22  |  12.3 KB  |  564 lines

  1. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  2. # Permission to use, copy, modify, and distribute this material 
  3. # for any purpose and without fee is hereby granted, provided 
  4. # that the above copyright notice and this permission notice 
  5. # appear in all copies, and that the name of Bellcore not be 
  6. # used in advertising or publicity pertaining to this 
  7. # material without the specific, prior written permission 
  8. # of an authorized representative of Bellcore.  BELLCORE 
  9. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  10. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  11. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  12.  
  13. # Conversion from C shell to Bourne shell by Z-Code Software Corp.
  14. # Conversion Copyright (c) 1992 Z-Code Software Corp.
  15. # Permission to use, copy, modify, and distribute this material
  16. # for any purpose and without fee is hereby granted, provided
  17. # that the above copyright notice and this permission notice
  18. # appear in all copies, and that the name of Z-Code Software not
  19. # be used in advertising or publicity pertaining to this
  20. # material without the specific, prior written permission
  21. # of an authorized representative of Z-Code.  Z-CODE SOFTWARE
  22. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
  23. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",
  24. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  25.  
  26. # Brought into line with metamail 2.7 beta release Csh version
  27. #    Dave Shield    February 1994
  28.  
  29. if [ -z "$METAMAIL_TMPDIR" ]
  30. then METAMAIL_TMPDIR=/tmp
  31. fi
  32.  
  33. hname=`hostname`
  34. idctr=0
  35. MustDelete=0
  36. batchmode=0
  37. multipart=1
  38. if test ! -z "${SPLITSIZE:-}"
  39. then
  40.     splitsize=$SPLITSIZE
  41. else
  42.     splitsize=100000
  43. fi
  44.  
  45. ouputfile=""
  46. multipartsubtype="mixed"
  47. cdescrip="An object packed by metasend"
  48. isentity=0
  49. newid=`date | tr " :" "__"`
  50. cid="<${newid}_$idctr@${hname}>"
  51. idctr=`expr $idctr + 1`
  52.  
  53. while test ! -z "$*"
  54. do
  55.     case $1 in
  56.         -S) shift
  57.             if test -z "$*"
  58.             then
  59.             echo "-S requires a following argument, the SPLIT threshhold"
  60.             exit 1
  61.             fi
  62.             splitsize=$1
  63.             shift ;;
  64.  
  65.         -b) batchmode=1
  66.             shift ;;
  67.  
  68.         -c) shift
  69.             if test -z "$*"
  70.             then
  71.                 echo "-c requires a following argument, the CC address"
  72.             exit 1
  73.             fi
  74.             cc=$1
  75.             shift ;;
  76.  
  77.         -i) shift
  78.             if test -z "$*"
  79.             then
  80.             echo "-i requires a following argument, the Content-ID value"
  81.             exit 1
  82.             fi
  83.             cid=$1
  84.             shift ;;
  85.  
  86.         -I) shift
  87.             if test -z "$*"
  88.             then
  89.             echo "-I requires a following argument, the multipart Content-ID value"
  90.             exit 1
  91.             fi
  92.             multicid=$1
  93.             shift ;;
  94.  
  95.         -s) shift
  96.             if test -z "$*"
  97.             then
  98.             echo "-s requires a following argument, the SUBJECT"
  99.             exit 1
  100.             fi
  101.             subject=$1
  102.             shift ;;
  103.  
  104.         -t) shift
  105.             if test -z "$*"
  106.             then
  107.             echo "-t requires a following argument, the TO address"
  108.             exit 1
  109.             fi
  110.             to=$1
  111.             shift ;;
  112.  
  113.         -F) shift
  114.             if test -z "$*"
  115.             then
  116.             echo "-F requires a following argument, the FROM address"
  117.             exit 1
  118.             fi
  119.             from=$1
  120.             shift ;;
  121.  
  122.         -P) shift
  123.             if test -z "$*"
  124.             then
  125.             echo "-P requires a following argument, the preamble file name"
  126.             exit 1
  127.             fi
  128.             preamblefile=$1
  129.             shift ;;
  130.  
  131.         -e) shift
  132.             if test -z "$*"
  133.             then
  134.             echo "-e requires a following argument, the ENCODING value"
  135.             exit 1
  136.             fi
  137.             encode=$1
  138.             case "$encode" in
  139.             "base64")    encodingprog="mimencode -b";;
  140.             "x-uue")    encodingprog="uuencode \$datafile";;
  141.             "7bit")        encodingprog=cat;;
  142.             *)        encodingprog="mimencode -q"
  143.                     encode=quoted-printable ;;
  144.             esac
  145.             shift ;;
  146.  
  147.         -f) shift
  148.             if test -z "$*"
  149.             then
  150.             echo "-f requires a following argument, the DATA FILE"
  151.             exit 1
  152.             fi
  153.             datafile=$1
  154.             if test ! -r $datafile
  155.             then
  156.             echo The file $datafile does not exist
  157.             exit 1
  158.             fi
  159.             shift ;;
  160.  
  161.         -m) shift
  162.             if test -z "$*"
  163.             then
  164.             echo "-m requires a following argument, the MIME CONTENT-TYPE"
  165.             exit 1
  166.             fi
  167.             ctype=$1
  168.             if test "`echo $ctype | grep /`" = ""
  169.             then
  170.             echo Invalid content-type specified
  171.             exit 1
  172.             fi
  173.             shift ;;
  174.  
  175.         -o) shift
  176.             if test -z "$*"
  177.             then
  178.             echo "-o requires a following argument, the output file name"
  179.             exit 1
  180.             fi
  181.             outputfile=$1
  182.             shift ;;
  183.  
  184.         -/) shift
  185.             if test -z "$*"
  186.             then
  187.             echo "-/ requires a following argument, the multipart subtype"
  188.             exit 1
  189.             fi
  190.             multipartsubtype=$1
  191.             shift ;;
  192.  
  193.         -D) shift
  194.             if test -z "$*"
  195.             then
  196.             echo "-D requires a following argument, the Content-Description value"
  197.             exit 1
  198.             fi
  199.             cdescrip=$1
  200.             shift ;;
  201.  
  202.         -E) isentity=1
  203.             shift ;;
  204.  
  205.         -z) MustDelete=1
  206.             shift ;;
  207.  
  208.         -n) if test $isentity -ne 0
  209.             then
  210.             if test -z "${encode:-}"
  211.             then
  212.                 encode=7bit
  213.                 encodingprog=cat
  214.             fi
  215.             if test -z "${ctype:-}"
  216.             then
  217.                 ctype=bogus
  218.                 # Never used
  219.             fi
  220.             if test -z "${datafile:-}"
  221.             then
  222.                 echo One part is incomplete -- each part needs at least -f and -E
  223.                 exit 1
  224.             fi
  225.             else
  226.             if test -z "${ctype:-}" || test -z "${datafile:-}"
  227.             then
  228.                 echo One part is incomplete -- each part needs at least -f and -m
  229.                 exit 1
  230.             fi
  231.             fi
  232.             if test -z "${encode:-}"
  233.             then
  234.                 case "$ctype" in
  235.                 text*)    encodingprog="mimencode -q"
  236.                     encode=quoted-printable ;;
  237.                 *)    encodingprog="mimencode -b"
  238.                     encode=base64 ;;
  239.             esac
  240.             fi
  241.             eval ctype${multipart}=\"$ctype\"
  242.             eval datafile${multipart}=$datafile
  243.             eval encode${multipart}=$encode
  244.             eval cdescrip${multipart}=\"$cdescrip\"
  245.             eval cid${multipart}=\"$cid\"
  246.             eval isentity${multipart}=$isentity
  247.             eval encodingprog${multipart}=\"\$encodingprog\"
  248.  
  249.             ctype=""
  250.             datafile=""
  251.             encode=""
  252.             encodingprog=""
  253.             newid=`date | tr " :" "__"`
  254.             cid="<${newid}_$idctr@${hname}>"
  255.             idctr=`expr $idctr + 1`
  256.             cdescrip="An object packed by metasend"
  257.             isentity=0
  258.             multipart=`expr $multipart + 1`
  259.             shift ;;
  260.  
  261.         *) echo UNRECOGNIZED METASEND OPTION: $1
  262.            exit 1 ;;
  263.     esac
  264. done
  265.  
  266. if test $batchmode -eq 0
  267. then
  268.     if test -z "${to:-}"
  269.     then
  270.         echo-n "To: "
  271.         read to
  272.     fi
  273.     if test -z "${subject:-}"
  274.     then
  275.             echo-n "Subject: "
  276.         read subject
  277.     fi
  278.     if test -z "${cc:-}"
  279.     then
  280.         echo-n "CC: "
  281.         read cc
  282.     fi
  283.  
  284.     anotherpart=1
  285.     while test $anotherpart -eq 1
  286.     do
  287.         looping=1
  288.         while test $looping -ne 0
  289.         do
  290.             if test -z "${ctype:-}"
  291.             then
  292.                 echo-n "Content-type: "
  293.             read ctype
  294.         fi
  295.         if test "`echo $ctype | grep /`" = ""
  296.         then
  297.             echo Invalid content-type specified
  298.             ctype=""
  299.         else
  300.             looping=0
  301.         fi
  302.         done
  303.         if test -z "${datafile:-}"
  304.         then
  305.         looping=1
  306.         while test $looping -eq 1
  307.         do
  308.             echo-n "Name of file containing $ctype data: "
  309.             read datafile
  310.             if test -r "$datafile"
  311.             then
  312.                 looping=0
  313.             else
  314.                 echo "The file $datafile does not exist."
  315.             fi
  316.         done
  317.         fi
  318.  
  319.         if test -z "${encode:-}"
  320.         then
  321.         looping=1
  322.         while test $looping -eq 1
  323.         do
  324.             echo "Do you want to encode this data for sending through the mail?"
  325.             echo "  1 -- No, it is already in 7 bit ASCII"
  326.             echo "  2 -- Yes, encode in base64 (most efficient)"
  327.             echo "  3 -- Yes, encode in quoted-printable (less efficient, more readable)"
  328.             echo "  4 -- Yes, encode it using uuencode (not standard, being phased out)"
  329.             read encode
  330.             looping=0
  331.             case "$encode" in
  332.                 1) encodingprog=cat
  333.                    encode=7bit ;;
  334.                 2) encodingprog="mimencode -b"
  335.                    encode=base64 ;;
  336.                 3) encodingprog="mimencode -q"
  337.                    encode=quoted-printable ;;
  338.                 4) encodingprog="uuencode $datafile"
  339.                    encode=x-uue ;;
  340.                 *) echo Unrecognized answer, please try again.
  341.                    looping=1 ;;
  342.             esac
  343.         done
  344.         fi
  345.  
  346.         echo-n "Do you want to include another file too (y/n) [n] ? "
  347.         read ans
  348.         case $ans in
  349.         [Yy]*)    
  350.             eval ctype${multipart}=\"$ctype\"
  351.             eval datafile${multipart}=$datafile
  352.             eval encode${multipart}=$encode
  353.             eval encodingprog${multipart}=\"\$encodingprog\"
  354.             eval cdescrip${multipart}=\"$cdescrip\"
  355.             eval cid${multipart}=\"$cid\"
  356.             eval isentity${multipart}=$isentity
  357.             cdescrip="An object packed by metasend"
  358.             isentity=0
  359.             ctype=""
  360.             datafile=""
  361.             encode=""
  362.             encodingprog=""
  363.             newid=`date | tr " :" "__"`
  364.             cid="<${newid}_$idctr@${hname}>"
  365.             idctr=`expr $idctr + 1`
  366.             multipart=`expr $multipart + 1`
  367.             ;;
  368.         *)
  369.             anotherpart=0;;
  370.         esac
  371.     done
  372.  
  373. else
  374.     if test -z "${outputfile:-}"
  375.     then
  376.         if test -z "${to:-}" \
  377.         -o -z "${subject:-}" \
  378.         -o -z "${ctype:-}" \
  379.         -o -z "${datafile:-}"
  380.         then
  381.         echo "metasend: in batch mode, if output is not directed to a file,  -t, -s, -f, and -m are all required"
  382.         exit 1
  383.         fi
  384.     else
  385.         if test -z "${datafile:-}"
  386.         then
  387.         echo "metasend: in batch mode, -f is required."
  388.         exit 1
  389.         fi
  390.         if test $isentity -ne 0
  391.         then
  392.             if test -z "${ctype:-}"
  393.             then
  394.             ctype=bogus
  395.             #  will not be used anyway
  396.         fi
  397.         fi
  398.         if test -z "${ctype:-}"
  399.         then
  400.         echo "metasend: in batch mode, with output directed to a file, -E or -m is required."
  401.         exit 1
  402.         fi
  403.     fi
  404.  
  405.  
  406.     if test ! -r $datafile
  407.     then
  408.         echo "metasend: The file $datafile does not exist"
  409.         exit 1
  410.     fi
  411.  
  412. #    if test -z "${cc:-}"
  413. #    then
  414. #        cc=''
  415. #    fi
  416.  
  417.     if test -z "${encode:-}"
  418.     then
  419.         case "$ctype" in
  420.             text*) encodingprog="mimencode -q"
  421.                    encode=quoted-printable ;;
  422.             *) encodingprog="mimencode -b"
  423.                encode=base64 ;;
  424.         esac
  425.     else
  426.         case "$encode" in
  427.             base64) encodingprog="mimencode -b" ;;
  428.             x-uue)  encodingprog="uuencode $datafile" ;;
  429.             7bit)   encodingprog=cat ;;
  430.             *) encodingprog="mimencode -q"
  431.                encode=quoted-printable ;;
  432.         esac
  433.     fi
  434. fi
  435.  
  436. if test -z "${encode:-}"
  437. then
  438.     case "$ctype" in
  439.         text*) encodingprog="mimencode -q"
  440.                encode=quoted-printable ;;
  441.         *) encodingprog="mimencode -b"
  442.            encode=base64 ;;
  443.     esac
  444. fi
  445.  
  446. eval ctype${multipart}=\"$ctype\"
  447. eval datafile${multipart}=$datafile
  448. eval encode${multipart}=$encode
  449. eval cdescrip${multipart}=\"$cdescrip\"
  450. eval cid${multipart}=\"$cid\"
  451. eval isentity${multipart}=$isentity
  452. eval encodingprog${multipart}=\"\$encodingprog\"
  453.  
  454. fname=$METAMAIL_TMPDIR/metasend.$$
  455. echo "MIME-Version: 1.0" > $fname
  456.  
  457. if test ! -z "${to:-}"
  458. then echo "To: $to" >> $fname
  459. fi
  460. if test ! -z "${subject:-}"
  461. then echo "Subject: $subject" >> $fname
  462. fi
  463. if test ! -z "${cc:-}"
  464. then echo "CC: $cc" >> $fname
  465. fi
  466. if test ! -z "${from:-}"
  467. then echo "From: $from" >> $fname
  468. fi
  469.  
  470. if test $multipart -gt 1
  471. then
  472.     boundary=${hname}.$$.`date | tr "  " .`
  473.     newid=`date | tr " :" "__"`
  474.     if test ! -z "${multicid:-}"
  475.     then
  476.         echo "Content-ID: $multicid" >> $fname
  477.     else
  478.         echo "Content-ID: ${newid}_$idctr@${hname}" >> $fname
  479.         idctr=`expr $idctr + 1`
  480.     fi
  481.     echo "Content-type: multipart/$multipartsubtype;" >> $fname
  482.     echo "    boundary="\"$boundary\" >> $fname
  483.     echo "" >> $fname
  484.     if test ! -z "${preamblefile:-}"
  485.     then
  486.         cat $preamblefile >> $fname
  487.     else
  488.         echo "This is  a multimedia message in MIME  format.  If you are reading this" >> $fname
  489.         echo "prefix, your mail reader does  not understand MIME.  You may wish" >> $fname
  490.         echo "to look into upgrading to a newer version of  your mail reader." >> $fname
  491.     fi
  492.  
  493.     i=1
  494.     while test $multipart -ge $i
  495.     do
  496.         echo "" >> $fname
  497.         echo --$boundary >> $fname
  498.         eval isentity=\$isentity$i
  499.  
  500.         if test $isentity -eq 0
  501.         then
  502.             eval echo "Content-ID: \$cid$i" >> $fname
  503.             eval echo "Content-type: \$ctype$i" >> $fname
  504.             eval echo "Content-Description: \$cdescrip$i" >> $fname
  505.             eval echo "Content-Transfer-Encoding: \$encode$i" >> $fname
  506.             echo "" >> $fname
  507.         fi
  508.         eval \$encodingprog$i \< \$datafile$i \>\> $fname
  509.         i=`expr $i + 1`
  510.     done
  511.     echo "" >> $fname
  512.     echo --${boundary}-- >> $fname
  513.     echo "" >> $fname
  514. else
  515.     if test $isentity -eq 0
  516.     then
  517.         echo "Content-ID: $cid" >> $fname
  518.         echo "Content-type: $ctype" >> $fname
  519.         echo "Content-Description: $cdesrip" >> $fname
  520.         echo "Content-Transfer-Encoding: $encode" >> $fname
  521.     fi
  522.     echo "" >> $fname
  523.     $encodingprog < $datafile >> $fname
  524.     # Ensure last line has trailing carriage return
  525.     echo "" >> $fname
  526. fi
  527.  
  528. if test -z "${outputfile:-}"
  529. then
  530.     if test $batchmode = 0
  531.     then
  532.         echo-n "Delivering mail, please wait...  "
  533.     fi
  534.     splitmail -s $splitsize -d $fname
  535.  
  536.     if test $? -eq 0
  537.     then
  538.         if test $batchmode = 0
  539.         then
  540.             echo "Mail delivery apparently succeeded."
  541.         fi
  542.         rm -f $fname
  543.     elif test "$MustDelete" -eq 1
  544.     then
  545.         echo Mail delivery failed
  546.         rm -f $fname
  547.         exit -1
  548.     else
  549.         echo "Mail delivery failed, draft mail is in $fname"
  550.         exit -1
  551.     fi
  552. else
  553.     mv $fname $outputfile
  554.     if test $? -ne 0
  555.     then
  556.         exit -1
  557.     fi
  558. fi
  559. exit 0
  560.  
  561.  
  562.